import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Main {
    /**
     * 1811622227
     * 1819522227
     * 1821122227
     * 1821322227
     * 1821722227
     *
     * 180772227
     *
     * @param args
     */
    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {

                for (int k = 0; k < 10; k++) {

                    ThreadUtil.sleep(500);
                    String qq = "1" + i + j + k + "22227";
                    try {
                        HttpResponse exec = exec(qq);
                        System.out.println(qq + "  " + exec.body());
                        JSONObject body = JSONObject.parseObject(exec.body());
                        JSONObject result = body.getJSONObject("result");
                        if (result != null) {

                            JSONObject buddy = result.getJSONObject("buddy");
                            JSONArray list = buddy.getJSONArray("info_list");

                            list.forEach(info -> {

                                JSONObject infoJson = (JSONObject) info;

                                System.out.println(infoJson.getString("uin") + "  " + infoJson.getString("nick"));

                                String nick = infoJson.getString("nick");
                                if ("难得".trim().equals(nick.trim())) {
                                    System.err.println("qq: " + infoJson.getString("uin"));
                                    return;
                                }
                            });
                        }
                    } catch (Exception e) {
                        System.out.println("超时：" + qq);
                    }
                }
            }
        }

    }

    private static HttpResponse exec(String qq) {

        HttpRequest httpRequest = HttpUtil.createPost("https://find.qq.com/proxy/domain/cgi.find.qq.com/qqfind/buddy/search_v3")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) QQ/9.4.7.27805 Chrome/43.0.2357.134 Safari/537.36 QBCore/3.43.1298.400 QQBrowser/9.0.2524.400")
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Referer", "https://find.qq.com/index.html?version=1&im_version=5815&width=910&height=610&search_target=0")
                .header("Accept-Encoding", "gzip, deflate")
                .header("Accept", "application/json, text/javascript, */*; q=0.01")
                .header("Cookie", "RK=qDKcqvGvS0; pgv_pvid=6282626063; ptcz=14b0f6fd9e3287eb84dfb97f258749fb1ec9b0b50dbaffae740ea97ad9555bc8; uin=o595726017; skey=ZktoLxGVRm")
                .body("num=20&page=0&sessionid=0&keyword=" + qq + "&agerg=0&sex=0&firston=0&video=0&country=1&province=&city=&district=0&hcountry=1&hprovince=0&hcity=0&hdistrict=0&online=0&ldw=2041111021");

        if (RandomUtil.randomBoolean()) {
            httpRequest.header("Cookie", "RK=qDKcqvGvS0; pgv_pvid=6282626063; ptcz=14b0f6fd9e3287eb84dfb97f258749fb1ec9b0b50dbaffae740ea97ad9555bc8; uin=o595726017; skey=ZktoLxGVRm");
        } else {
            httpRequest.header("Cookie", "RK=sJ7UJoXuQK; pgv_info=ssid=s6702851385; pgv_pvid=4728717000; ptcz=adb99457821bd201549ae2a41467c277cb96a50dfb33d9619b61dc2fbd28aed9; uin=o869461518; skey=Z7uUTJzdfp");
        }
        return httpRequest.execute();
    }
}
